package utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @Description:
 * @Author: liyuhang
 * @CreateTime: 2021/3/28 7:28 下午
 * @Company:
 */
public class DateTimeFormatterUtils {

    private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    private static DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");

    public static String format(LocalDateTime localDateTime) {
        return dateTimeFormatter.format(localDateTime);
    }

    public static String format(LocalDate localDate) {
        return dateFormatter.format(localDate);
    }

    public static String format(LocalTime localTime) {
        return timeFormatter.format(localTime);
    }

    public static LocalDateTime parseLocalDateTime(String text){
        return LocalDateTime.parse(text, dateTimeFormatter);
    }

    public static LocalDate parseLocalDate(String text){
        return LocalDate.parse(text, dateFormatter);
    }

    public static LocalTime parseLocalTime(String text) {
        return LocalTime.parse(text, timeFormatter);
    }
}
